package com.techsun.json.format.defaultConfig.strategys;

import com.techsun.json.format.defaultConfig.data.constant.DefaultStrategyKeyConstant;
import com.techsun.json.format.defaultConfig.pattern.FormatPatternInterface;
import com.techsun.json.format.defaultConfig.util.InternationalFormatUtils;
import com.techusn.json.fromat.base.strategy.FormatStrategy;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author chenYX
 * @date 2021/8/19 11:43
 * @description
 */
@Component
public class DefaultCurrencyStrategy implements FormatStrategy<String,String> {

    @Resource
    private FormatPatternInterface formatPatternInterface;

    @Override
    public String getStrategyKey() {
        return DefaultStrategyKeyConstant.CURRENCY;
    }

    @Override
    public String formatData(String value, String[] attach) {
        //获取数字规则
        String numberPattern = formatPatternInterface.getNumberPattern();
        //货币规则
        String currencyPattern = formatPatternInterface.getCurrencyPattern();
        String numberStr = InternationalFormatUtils.formatNumberStr(numberPattern, value);
        return currencyPattern + StringUtils.EMPTY + numberStr;
    }
}
